package qc.module.platform.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import qc.module.platform.dto.log.ApiLogInfoDto;
import qc.module.platform.entity.QcApiLogs;

import java.util.ArrayList;
import java.util.List;

/**
 * ApiLogMapper
 *
 * @author QuCheng Tech
 * @create 2023/2/4
 */
@Mapper
public interface ApiLogMapper {
    ApiLogMapper MAPPER = Mappers.getMapper(ApiLogMapper.class);

    @Mapping(target = "tm", source = "tm", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(target = "ip", source = "host")//数据库表中的列名为host，DTO中统一为ip
    ApiLogInfoDto toDto(QcApiLogs en);

    List<ApiLogInfoDto> toDtoList(List<QcApiLogs> list);

    default List<ApiLogInfoDto> toQueryDtoList(List<QcApiLogs> list) {
        List<ApiLogInfoDto> dtos = new ArrayList<>();
        list.stream().forEach(en -> {
            ApiLogInfoDto dto = toDto(en);
            dtos.add(dto);
        });
        return dtos;
    }
}
